﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE;
using DAL;

namespace BLL
{
	public class EdgeWorker
	{
		EdgeDA DbInstance;

		public EdgeWorker()
		{
			DbInstance = new EdgeDA();
		}

		public Edge Get( int id )
		{
			return DbInstance.GetEdge( id );
		}

		public List<Edge> GetAll()
		{
			return DbInstance.GetAllEdges();
		}

		public int Add( Edge edge, String username )
		{
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Add;
            log.Event = "A walkway with following information has been added - Name: " + edge.Name + ", Meters: " + edge.Weight +
                ", Straight: " + edge.Straight + ", 1. Location ID: " + edge.L1 + ", 2. Location ID: " + edge.L2 + ", Directions: " + edge.Direction;

            lW.Add(log);

			return DbInstance.AddEdge( edge );
		}

		public int Edit( Edge edge, string username )
		{
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Edit;
            log.Event = "Walkway with ID = " + edge.ID + " has been updated to following - Name: " + edge.Name +
                ", Meters: " + edge.Weight + ", Staight: " + edge.Straight + ", 1. Location ID: " + edge.L1 +
                ", 2. Location ID: " + edge.L2 + ", Directions: " + edge.Direction;

            lW.Add(log);

			return DbInstance.EditEdge( edge );
		}

		public int Delete( Edge edge, string username )
		{
            LogWorker lW = new LogWorker();
            Log log = new Log();

            log.Time = DateTime.Now;
            log.User = username;
            log.Type = EventTypes.Edit;
            log.Event = "Walkway with ID = " + edge.ID + " has been deleted";

            lW.Add(log);

			return DbInstance.DeleteEdge( edge.ID );
		}
	}
}
